﻿CREATE VIEW dbo.v_CarInfo_10
AS
SELECT     CI.LoanID, LOAN.MsID, CAR.VIN, CAR.VIN_9, CAR.Mileage, CI.Used, CAR.Color, CI.Tag, ISNULL(CAR.Description, CI.Description) AS Description, 
                      CI.Price, CAR.Make, CAR.Model, CAR.Series, CAR.Body_Style, CAR.Year, CAR.Doors, CAR.CarInfoOther, D.State AS DealerState, 
                      CAR.Mileage / CAR.Year AS MilesPerYear, D_SP.DealerID, D.Name AS Dealer, D.Latitude, D.Longitude, D.Phone AS DealerPhone, 
                      D.Street + ',' + D.City + ',' + D.Zip AS DealerAddress, D.BranchID, LOAN.TitleOk, LOAN.LienHolderOnTitle, 
                      CAR.Make + ' ' + CAR.Model + ' ' + CAR.Series + ' ' + CAR.Body_Style AS MakeModelStyle, dbo.ModelAge(CAR.Year, ISNULL(LI.FirstPaymentDate, 
                      LOAN.EnterDate)) AS ModelAge, dbo.ModelAge(CAR.Year, GETDATE()) AS ModelAgeCurrent, dbo.MinInt(6, YEAR(ISNULL(LI.FirstPaymentDate, 
                      LOAN.EnterDate)) - CAR.Year + CASE WHEN MONTH(ISNULL(LI.FirstPaymentDate, LOAN.EnterDate)) > 7 THEN 1 ELSE 0 END) AS ModelAgeForAddOn, 
                      CAR.DescriptionMMR, LOAN.Ms_CLASS, LOAN.Ms_ACCOUNT, CI.BookValueOverride, CI.BookValueDescOverride, CAR.IsSUV, 
                      CAR.TrackingDeviceProviderID, CAR.TrackerTypeID, CAR.CarTypeID, D.IsIndependent, ISNULL(dbo.t_VehicleType_Clean.TruckDuty, 'U') AS TruckDuty, 
                      CI.BookValueCurrent, CI.BookValueCurrentTypeID, CI.BookValueCurrentDate, CI.BookValueProviderCode, D_SP.Name AS SalesPersonName, 
                      D.Fax AS DealerFax
FROM         dbo.t_LoanInfo AS LI INNER JOIN
                      dbo.t_Loan AS LOAN INNER JOIN
                      dbo.t_CarInfo AS CI ON LOAN.ID = CI.LoanID INNER JOIN
                      dbo.t_Dealer_SalesPersons AS D_SP ON LOAN.DealerSalesPersonID = D_SP.ID INNER JOIN
                      dbo.t_Dealer AS D ON D_SP.DealerID = D.ID ON LI.LoanID = LOAN.ID LEFT OUTER JOIN
                      dbo.t_VehicleType_Clean RIGHT OUTER JOIN
                      dbo.t_Car AS CAR ON dbo.t_VehicleType_Clean.VIN_8 = CAR.VIN_8 ON CI.VIN = CAR.VIN

GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane1', @value = N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[36] 4[47] 2[10] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[43] 4[31] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "LI"
            Begin Extent = 
               Top = 219
               Left = 231
               Bottom = 327
               Right = 432
            End
            DisplayFlags = 280
            TopColumn = 23
         End
         Begin Table = "LOAN"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 334
               Right = 218
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "CI"
            Begin Extent = 
               Top = 130
               Left = 261
               Bottom = 446
               Right = 473
            End
            DisplayFlags = 280
            TopColumn = 2
         End
         Begin Table = "D_SP"
            Begin Extent = 
               Top = 6
               Left = 446
               Bottom = 115
               Right = 597
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "D"
            Begin Extent = 
               Top = 6
               Left = 635
               Bottom = 115
               Right = 793
            End
            DisplayFlags = 280
            TopColumn = 6
         End
         Begin Table = "t_VehicleType_Clean"
            Begin Extent = 
               Top = 112
               Left = 921
               Bottom = 190
               Right = 1072
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "CAR"
            Begin Extent = 
               Top = 122
               Left = 575
               Bottom = 416
               Right = 805
            End
            DisplayFlags = 280', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_CarInfo_10';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane2', @value = N'TopColumn = 6
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 50
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 2190
         Width = 1500
         Width = 2100
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 8835
         Alias = 2040
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_CarInfo_10';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPaneCount', @value = 2, @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_CarInfo_10';

